{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# f_words = [\"转发\", \"分享\", \"红包\", \"抽奖\"]\n",
    "# c_words = [\"评论\", \"写上\",\"留言\"]\n",
    "# l_words = [\"点赞\", \"赞\"]\n",
    "f_words = [\"转发\"]\n",
    "c_words = [\"评论\"]\n",
    "l_words = [\"点赞\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 177923/177923 [00:15<00:00, 11756.42it/s]\n"
     ]
    }
   ],
   "source": [
    "# 使用用户中位数作为预测\n",
    "with open(\"User_state.json\",\"r\",encoding=\"utf-8\") as f:\n",
    "    user_state:dict = json.load(f)\n",
    "weibo_predict_data = pd.read_csv(\"./data/weibo_predict_data.txt\", sep=\"\\t\", header=None, names=[\"uid\", \"mid\", \"time\", \"content\"])\n",
    "file_out = []\n",
    "\n",
    "for index, row in tqdm(weibo_predict_data.iterrows(), total=len(weibo_predict_data)):\n",
    "    f_time = 1\n",
    "    c_time = 1\n",
    "    l_time = 1\n",
    "    content = row[\"content\"]\n",
    "    if not pd.isna(content):\n",
    "        if any(word in content for word in f_words):\n",
    "            f_time = 1.15\n",
    "        if any(word in content for word in c_words):\n",
    "            c_time = 1.15\n",
    "        if any(word in content for word in l_words):\n",
    "            l_time = 1.15\n",
    "    if row[\"uid\"] in user_state.keys():\n",
    "        file_out.append(\"{0}\\t{1}\\t{2},{3},{4}\\n\".format(row[\"uid\"],row[\"mid\"],round(f_time*user_state[row[\"uid\"]][\"forward_median\"]),round(c_time*user_state[row[\"uid\"]][\"comment_median\"]),round(l_time*user_state[row[\"uid\"]][\"like_median\"])))\n",
    "    else:\n",
    "        file_out.append(\"{0}\\t{1}\\t{2},{3},{4}\\n\".format(row[\"uid\"],row[\"mid\"],0,0,0))\n",
    "with open(\"answer_user_state.txt\", \"w\", encoding=\"utf-8\") as f:\n",
    "    f.writelines(file_out)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
